GetCooperativeAction   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 19
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 2
eloc 19
dl 0
loc 19
c 0
b 0
f 0
rs 10

1 Function

Rating   Name   Duplication   Size   Complexity  
A index 0 9 2
1
import {
2
  Controller,
3
  Inject,
4
  UseGuards,
5
  Get,
6
  NotFoundException
7
} from '@nestjs/common';
8
import { AuthGuard } from '@nestjs/passport';
9
import { ApiTags, ApiBearerAuth, ApiOperation } from '@nestjs/swagger';
10
import { IQueryBus } from 'src/Application/IQueryBus';
11
import { GetCooperativeQuery } from 'src/Application/Settings/Query/GetCooperativeQuery';
12
import { CooperativeView } from 'src/Application/Settings/View/CooperativeView';
13
import { UserRole } from 'src/Domain/HumanResource/User/User.entity';
14
import { Roles } from 'src/Infrastructure/HumanResource/User/Decorator/Roles';
15
import { RolesGuard } from 'src/Infrastructure/HumanResource/User/Security/RolesGuard';
16
17
@Controller('settings')
18
@ApiTags('Settings')
19
@ApiBearerAuth()
20
@UseGuards(AuthGuard('bearer'), RolesGuard)
21
export class GetCooperativeAction {
22
  constructor(
23
    @Inject('IQueryBus')
24
    private readonly queryBus: IQueryBus
25
  ) {}
26
27
  @Get('cooperative')
28
  @Roles(UserRole.COOPERATOR, UserRole.EMPLOYEE)
29
  @ApiOperation({ summary: 'Get cooperative settings' })
30
  public async index(): Promise<CooperativeView> {
31
    try {
32
      return await this.queryBus.execute(new GetCooperativeQuery());
33
    } catch (e) {
34
      throw new NotFoundException(e.message);
35
    }
36
  }
37
}
38